﻿@using Abp.Application.Services.Dto;
@using FwProject.Restaurant.Dto
@{
    ViewBag.Title = "盘点";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">

                </div>
            </div>
            <div class="ibox-content" style="height:700px">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" asp-controller="Restaurant" asp-action="RestaurantStockCheck" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback">
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">单号：</label>
                                <div class="input-group">
                                    <input type="text" name="" class="input-sm form-control" value="系统自动生成" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">盘点日期：</label>
                                <div class="input-group">
                                    <input type="text" name="CreationTime" id="CreationTime" class="input-sm form-control" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            @*<div class="col-md-4">
                                    <label class="control-label col-md-3">餐厅名称：</label>
                                    <div class="input-group">
                                        <input type="text" name="RestaurantId" class="input-sm form-control" value="">
                                    </div>
                                </div>*@
                            <div class="col-md-4">
                                <label class="control-label col-md-3">餐厅：</label>
                                <div class="input-group" style="width:162px">
                                    <input type="hidden" name="RestaurantId" id="RestaurantId" />
                                    <input type="text" id="dropdown-driverid" class="form-control" onblur="blurEmpty()" placeholder="全部">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown" style="line-height:1.455;padding:6px 12px;">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu" style="z-index: 9999;"></ul>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">经办人：</label>
                                <div class="input-group">
                                    <select class="input-s form-control" name="Person">
                                        @{ var i = 0;}
                                        @foreach (var item in ViewBag.Person)
                                        {
                                            if (i == 0)
                                            {
                                                <option value="@item.Name" selected="selected">@item.Name</option>
                                            }
                                            else
                                            {
                                                <option value="@item.Name">@item.Name</option>
                                            }

                                        }
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6">
                                <label class="control-label col-md-2">备注：</label>
                                <div class="input-group">
                                    <textarea class="form-control" name="RemarkContent" style="width:400px"></textarea>
                                </div>
                            </div>
                        </div>
                        <hr />
                        <div class="form-group">
                            <div class="col-md-4">
                                <label class="control-label col-md-3">应存数量：</label>
                                <div class="input-group">
                                    <input type="text" name="Count" id="Count" class="input-sm form-control" value="0" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">盘点数量：</label>
                                <div class="input-group">
                                    <input type="text" name="CheckCount" id="CheckCount" class="input-sm form-control" value="0" oninput="Change(this)">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="control-label col-md-3">盈亏数量：</label>
                                <div class="input-group">
                                    <input type="text" name="ProfitCount" id="ProfitCount" class="input-sm form-control" value="0" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <br />
                        <div class="ibox-tools">
                            @if (IsGranted(FwProject.Authorization.PermissionNames.Distribution_Operation_Inventory))
                            {
                                <button type="submit" class="btn btn-primary btn btn-sm">提交</button>
                            }
                            else
                            {
                                <button type="button" class="btn btn-default btn btn-sm">无盘点权限</button>
                            }

                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script>
        $(document).ready(function () {
            $.getJSON("/Restaurant/GetSuggestData").done(function (data) {
                CommonAjaxCallback(data, function () {
                    bindSuggest(data.result);
                }, null);
            }).fail(function () {
                layer.msg('连接超时，获取司机信息失败！', {
                    icon: 2,
                    time: 2000
                });
            });

            $('#CreationTime').datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true
            })
        })
        function bindSuggest(data) {
            if ($("#dropdown-driverid") != undefined) {
                $role = $("#dropdown-driverid").bsSuggest({
                    effectiveFields: ["restaurantName"],
                    effectiveFieldsAlias: { "restaurantName": "餐厅名称" },
                    searchFields: ["restaurantName"],
                    clearable: true,
                    getDataMethod: "data",
                    callfun: function () {
                        $("#RestaurantId").val("");
                    },
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "restaurantName",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $.post("/Restaurant/GetRestaurantTypeNumberCount", { "Id": "" + data.id + "" }, function (e) {

                        $('#Count').val(e.result);

                        setCount();
                    });

                    $("#RestaurantId").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }
        function blurEmpty() {
            var cityObj = $("#dropdown-driverid");
            var DriverId = $("#RestaurantId");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }

        function Change(obj) {
            setCount();
        }

        function setCount() {

            var CheckCount = parseInt($("#CheckCount").val());
            if (CheckCount < 0) {

                $('#CheckCount').val(0);
                CheckCount = 0;
            }


            var Count = $('#Count').val();
            $('#ProfitCount').val(CheckCount - Count);

        }
        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $("#RestaurantId").val("");
                $("#dropdown-driverid").val("");
                $("#CreationTime").val("");
                $("#CheckCount").val("0")

            }, successInfo);
        }
    </script>
}